package com.youchuang.action.user;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;
import com.youchuang.action.BaseAction;
import com.youchuang.bean.Comment;
import com.youchuang.bean.User;
import com.youchuang.common.Constant;
import com.youchuang.service.IndentService;
import com.youchuang.service.UserService;

/**
 * 用户评论订单和图书，信息插入数据库
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/user")
@ParentPackage("shopping-default")
public class InsertCommenttwoAction extends BaseAction {
	private Logger logger = Logger.getLogger(InsertCommenttwoAction.class.getSimpleName());
	private String productId;
	private String productName;
	private String st;
	private String sqf;
	private String sqs;
	private String commentText;
	private String indentId;

	@Resource
	private UserService userService;
	@Resource
	private IndentService indentService;

	@Action(value = "insertCommentTwo", results = {
			@Result(name = ActionSupport.SUCCESS, location = "/WEB-INF/jsp/user/comment_indent.jsp") })
	public String execute() throws Exception {
		logger.info("method is execute");
		int totlRank = 0;
		int expressRank = 0;
		int productRank = 0;
		if (st.equals(Constant.BAD)) {
			totlRank = 1;
		} else if (st.equals(Constant.GENERAL)) {
			totlRank = 2;
		} else if (st.equals(Constant.GOOD)) {
			totlRank = 3;
		} else if (st.equals(Constant.VERY_GOOD)) {
			totlRank = 4;
		} else if (st.equals(Constant.VERY_WELL)) {
			totlRank = 5;
		}
		if (sqf.equals(Constant.BAD)) {
			expressRank = 1;
		} else if (sqf.equals(Constant.GENERAL)) {
			expressRank = 2;
		} else if (sqf.equals(Constant.GOOD)) {
			expressRank = 3;
		} else if (sqf.equals(Constant.VERY_GOOD)) {
			expressRank = 4;
		} else if (sqf.equals(Constant.VERY_WELL)) {
			expressRank = 5;
		}
		if (sqs.equals(Constant.BAD)) {
			productRank = 1;
		} else if (sqs.equals(Constant.GENERAL)) {
			productRank = 2;
		} else if (sqs.equals(Constant.GOOD)) {
			productRank = 3;
		} else if (sqs.equals(Constant.VERY_GOOD)) {
			productRank = 4;
		} else if (sqs.equals(Constant.VERY_WELL)) {
			productRank = 5;
		}

		User user = (User) session.get(Constant.S_USER);
		Comment com = new Comment();
		com.setCommentText(commentText);
		com.setExpressRank(expressRank);
		com.setNickName(user.getNickName());
		com.setProductId(productId);
		com.setProductName(productName);
		com.setProductRank(productRank);
		com.setTime(System.currentTimeMillis());
		com.setTotolRank(totlRank);
		com.setUserId(user.getId());

		userService.saveComment(com);

		indentService.updateIndent(indentId, Constant.INDENT_AFFIRM);

		return Constant.SUCCESS;
	}

	public String getProductId() {
		return productId;
	}

	public void setProductId(String productId) {
		this.productId = productId;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public String getSt() {
		return st;
	}

	public void setSt(String st) {
		this.st = st;
	}

	public String getSqf() {
		return sqf;
	}

	public void setSqf(String sqf) {
		this.sqf = sqf;
	}

	public String getSqs() {
		return sqs;
	}

	public void setSqs(String sqs) {
		this.sqs = sqs;
	}

	public String getCommentText() {
		return commentText;
	}

	public void setCommentText(String commentText) {
		this.commentText = commentText;
	}

	public String getIndentId() {
		return indentId;
	}

	public void setIndentId(String indentId) {
		this.indentId = indentId;
	}

}
